package com.ormlite.activity.modify;

import android.os.Bundle;
import android.util.SparseIntArray;
import android.widget.Spinner;

import com.ormlite.activity.tool.DatabaseUtils;
import com.ormlite.activity.tool.GuiUtils;
import com.ormlite.activity.tool.Utils;
import com.ormlite.activity.tool.button.BackButton;
import com.ormlite.activity.tool.button.event.ModifyUpdateEventButton;
import com.ormlite.app.R;

public final class ModifyEventActivity extends AbstractModifyActivity {

	private final SparseIntArray positionToId = new SparseIntArray();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_modify_event);

		Integer id = Integer.valueOf(getIntent().getExtras().getInt("id"));
		String name = Utils.getExtraFromActivity(this, "name");
		String time = Utils.getExtraFromActivity(this, "time");
		String comment = Utils.getExtraFromActivity(this, "comment");

		Spinner spinner = (Spinner) findViewById(R.id.spinnerModify);
		spinner.setAdapter(DatabaseUtils.createAdapter(this, positionToId));

		GuiUtils.setDefaultEditText(this, R.id.nameEditModify, name);
		GuiUtils.setDefaultEditText(this, R.id.dateEditModify, time);
		GuiUtils.setDefaultEditText(this, R.id.commentEditModify, comment);

		GuiUtils.hookButton(this, R.id.buttonBack, new BackButton(this));
		GuiUtils.hookButton(this, R.id.modifyEvent, new ModifyUpdateEventButton(this, id, spinner));
	}
}
